﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Kohvik_KohvikuKomm : System.Web.UI.Page
{
    private int kId ;
    private int? uId ;
    private string uNa ;
    private string uDi ;

    protected void Page_Load ( object sender , EventArgs e )
    {
        if ( Session [ "sess" ] == null ) Session [ "sess" ] = SessionStatic . CreateSession () ;
        SessionData sesDat = SessionStatic . GetData ( ( int ) Session [ "sess" ] ) ;
        uId = sesDat . UserId ;
        uNa = ( uId != null ) ? sesDat . UserName : SETS . ANONYMOUS_NA ;
        uDi = ( uId != null ) ? sesDat . UserDisp : SETS . ANONYMOUS_NA ;

//http://localhost:53017/KohvikuProjekt/Kohvik/KohvikuKomm.aspx?id=1
        if ( Request . QueryString [ "id" ] == null ) Response . Redirect ( SETS.IDLINKCAFEPAGE+"1" ) ;//FIXME: AJUTINE TEST!!
        //if ( Request . QueryString [ "id" ] == null ) Response . Redirect ( "~/Default.aspx" ) ;
        int id ;
        if ( int . TryParse ( Request . QueryString [ "id" ] , out id ) ) kId = id ;
          else Response . Redirect ( "~/Default.aspx" ) ;

        byte sets ;
        switch ( sesDat . AskRole ( kId ) ) {
          case ROLE . ADMIN :
            sets = SETS . CAFECA ; break ;
          case ROLE . OMANIK :
            sets = SETS . CAFECM ; break ;
          case ROLE . KLIENT : case ROLE . ANONYYMNE :
            sets = SETS . CAFECU ; break ;
          default :
            sets = SETS . CAFECU ; break ; }

        CommInControl1 . Sets = sets ;
        CommOutControl1 . Sets = sets ;
        CommInControl1 . SetVals ( kId , uId , uNa , uDi ) ;
        CommOutControl1 . SetVals ( kId , uId , uNa , uDi ) ;
    }
}